<template>
  <el-card class="box-card">
    <el-tabs v-model="activeDetail">
      <el-tab-pane label="登入账号设置" name="loginInfo">
        <el-form
          ref="baseForm"
          label-width="80px"
          style="margin:50px auto;width:400px"
          :model="userInfo"
          :rules="rules"
        >
          <el-form-item label="姓名" prop="username">
            <el-input v-model="userInfo.username"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="userInfo.password" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="saveProfile">更新</el-button>
            <el-button @click="$router.push({ path: '/employees' })"
              >取消</el-button
            >
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人详情" name="userInfo">
        <user-info />
      </el-tab-pane>
      <el-tab-pane label="岗位信息" name="jobInfo">
          <job-info />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { userProfile } from '@/api/user'
import { saveProfile } from '@/api/employees'
import userInfo from './components/user-info.vue'
import jobInfo from './components/job-info.vue'
export default {
  data () {
    return {
      activeDetail: 'loginInfo',
      userInfo: {},
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  components: {
    userInfo,jobInfo
  },
  created () {
    this.getBaseProfile()
  },
  methods: {
    async getBaseProfile () {
      let res = await userProfile(this.$route.query.id)
      this.userInfo = res.data
      // this.userInfo.password = ''
    },
    saveProfile () {
      this.$refs.baseForm.validate(async v => {
        if (v) {
          await saveProfile(this.userInfo)
          this.$message.success('修改成功!')
          //   this.$router.push({path:'/employees'})
          this.$router.go(-1)
          //   this.$router.back()
        }
      })
    }
  }
}
</script>

<style lang="scss"></style>
